home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / asmutil / asm_n_z.zip / WT.ASM < prev    next >
Assembly Source File  |  1987-03-12  |  23KB  |  471 lines

  1.         TITLE   WalkTree - Execute Program at Every Level of Tree
  2.  
  3. ; Copyright Notice:
  4. ; The program WalkTree,  both in binary executable and source forms,  is 
  5. ; in  the  public  domain.  No  warranty  is  given  or implied,  and no 
  6. ; liability will be assumed by the author.  
  7. ; Everyone on earth is hereby given permission to use, copy, distribute, 
  8. ; change, mangle,  destroy or otherwise employ these programs,  in whole 
  9. ; or in part,  in any fashion they so desire,  provided they hurt no one 
  10. ; but themselves in the process.  
  11. ; If anyone has any questions about this or any  other  program  that  I 
  12. ; have  authored,  I  can be reached by messages on any of the following 
  13. ; systems: 
  14. ;     Bob's Answering Machine      (602) 242-3158   300/1200 bps
  15. ;     FIDO 114/1 Phoenix Node      (602) 242-5230   300/1200/2400 bps
  16. ;     FIDO 114/446 XTRA #1         (602) 979-6352   300/1200/2400 bps
  17. ;     Technoids Anonymous          (602) 899-4876   300/1200/2400 bps
  18. ; All excellent 24 hour systems.
  19. ; Don A. Williams
  20. ; 3913 W. Solano Dr. N.
  21. ; Phoenix, AZ 85019
  22.  
  23.  
  24. ; This version of the source for WalkTree has been set up for assembly by
  25. ; SpeedWare's very good TurboEditAsm.  To convert it for assembly by
  26. ; Microsoft's MASM will require the addition of Segment and Assume
  27. ; statements, at least.
  28. ;
  29. ;
  30. ;   version history
  31. ;   modified by John Covici
  32. ;   3 Wirt Street NW
  33. ;   Leesburg, VA 22075
  34. ;   March 12, 1987 fixed the following bugs: 
  35. ;     (1) append cr to generated command line (if not dos goes out to lunch)
  36. ;     (2) now assembles with masm
  37. ;     (3) to get environment segment had to say [ds:2ch] instead of [2ch]
  38. ;        otherwise assembler ignored brackets without error
  39.  
  40. LF      EQU     0AH                     ; ASCII Line Feed
  41. CR      EQU     0DH                     ; ASCII Carriage Return
  42.  
  43.  
  44. cseg segment para public 'code'
  45.         ORG     0100H
  46.  assume cs:cseg,ds:cseg,ss:cseg
  47. Start:  jmp     Begin                   ; Jump over data area
  48.  
  49. ;------  Messages
  50.  
  51. LogOn   db      'WalkTree:  Version 1.01 - March 12, 1987',CR,LF,LF,'$'
  52.  
  53. BadVer  db      'WalkTree requires Dos 2.0 or greater',CR,LF,'$'
  54.  
  55. UseMsg  db      'USAGE:  WalkTree <any dos command>',CR,LF,'$'
  56.  
  57. EndMs1  db      CR,LF,'Number of directories= $'
  58. EndMs2  db      ': Maximum depth= $'
  59. EndMsg  db      '$'
  60.  
  61. AbtMsg  db      'Program terminated by operator.',CR,LF,'$'
  62.  
  63. ;------ Constants and Other Data Storage
  64.  
  65. Path    db      0,':\',65 DUP(0)
  66.  
  67. PatMsg  db      CR,LF,LF,'---'
  68. CurPat  db      0,':\',65 DUP(0)
  69. PatTer  db      '---',CR,LF,0
  70.  
  71.  
  72. MatAll  db      '*.*',0
  73.  
  74. Parent  db      '..',0
  75.  
  76. CmdTail db      0,'/c '
  77. CmdLin  db      128 DUP(0)
  78.  
  79. ComSpc  db      'COMSPEC',0
  80.  
  81. ComCom  db      '\COMMAND.COM',0
  82.  
  83. DTAOfs  dw      0                       ; Save space for DTA: Offset and
  84. DTASeg  dw      0                       ; ... Segment
  85.  
  86. SaveSS  dw      0                       ; Save space for Stack; Segment and
  87. SaveSP  dw      0                       ; ... Pointer
  88.  
  89. Level   dw      0                       ; Current depth in hierarchy
  90. MaxLev  dw      0                       ; Maximum depth in hierarchy
  91.  
  92. DirCnt  dw      0                       ; Count of directories processed
  93. comand db 65 dup(0) ;space for command.com from env or default
  94.  
  95. ;------  Parameter Block for DOS function 4B, Exec
  96.  
  97. ParBlk  dw      0                       ; Seg of environment string
  98.         dw      0                       ; Ofs of Command Tail string
  99.         dw      0                       ; Seg "     "      "     "
  100.         dw      0                       ; Ofs of Default FCB 1
  101.         dw      0                       ; Seg "     "     "  "
  102.         dw      0                       ; Ofs of Default FCB 2
  103.         dw      0                       ; Seg "     "     "  "
  104.  
  105. ;=========================================================================
  106. ; Beginning of Program Code
  107.  
  108. Begin:  mov     SP,offset STACK         ; Set local stack
  109.         cld                             ; Clear Direction Flag [forward]
  110.         mov     DX,offset LogOn         ; Dsiplay logon message
  111.         mov     AH,9                    ; ... MS-DOS 'Print String'
  112.         int     21H                     ; ... DOS Entry Interrupt
  113.         mov     AH,30H                  ; MS-DOS 'Get Version'
  114.         int     21H                     ; ... DOS Entry Interrupt
  115.         cmp     AL,2                    ; Check for 2.x or greater
  116.         jnb     VerOk                   ; ... Xfr- 2.x or greater
  117.         mov     DX,offset BadVer        ; Get ptr to 'bad version' msg
  118. ErrorExit:
  119.         mov     AH,9                    ; MS-DOS 'Print String'
  120.         int     21H                     ; ... DOS Entry Interrupt
  121.         int     20H                     ; DOS Terminate Program Interrupt
  122.  
  123. VerOk:  mov     AH,19H                  ; MS-DOS 'Get Current Disk'
  124.         int     21H                     ; ... DOS Entry Interrupt
  125.         add     AL,'A'                  ; Convert disk code to alpha disk
  126.         mov     Path,AL                 ; ... and save in Path
  127.         mov     CurPat,AL               ; ... and in Current Path
  128.         mov     SI,offset Path+3        ; Get Current Dir as starting path
  129.         mov     DL,0                    ; ... current disk
  130.         mov     AH,47H                  ; ... MS-DOS 'Get Current Directory'
  131.         int     21H                     ; ... DOS Entry Interrupt
  132.         mov     SI,80H                  ; Get ptr to Command Line buffer
  133.         lodsb                           ; ... and get length
  134.         or      AL,AL                   ; Check for length zero - no tail
  135.         jnz     HaveTail                ; ... Xfr - length not zero
  136. Usage:
  137.         mov     DX,offset UseMsg        ; Display 'Usage' message and
  138.         jmp     short ErrorExit         ; ... terminate
  139.  
  140. HaveTail:
  141.         cbw                             ; Make length 16 bits
  142.         mov     CX,AX                   ; ... and move to CX for move
  143.         add     AL,3                    ; Adjust length for '/c '
  144.         mov     CmdTail,AL              ; ... and store for DOS 4BH
  145.         mov     DI,offset CmdLin        ; Get ptr to internal Cmnd Line
  146.         repz    movsb                   ; Move command line to internal store
  147.  mov byte ptr[di],0dh ;append carriage return
  148.         mov     BX,1000H                ; Release all but 1000H paragraphs
  149.         mov     AH,4AH                  ; ... MS-DOS 'Modify Allocated Memory'
  150.         int     21H                     ; ... DOS Entry Interrupt
  151.         call    WalkTree                ; Walk the tree recursively
  152.         mov     DX,offset EndMs1        ; Print out run statistics
  153.         mov     AH,9                    ; ... MS-DOS 'Print String'
  154.         int     21H                     ; ... DOS Entry Interrupt
  155.         mov     BX,DirCnt               ; Display directory count in
  156.         call    PrintDecimal            ; ... decimal
  157.         mov     DX,offset EndMs2        ; Display 2nd part of message
  158.         mov     AH,9                    ; ... MS-DOS 'Print String'
  159.         int     21H                     ; ... DOS Entry Interrupt
  160.         mov     BX,MaxLev               ; Display maximum level in
  161.         call    PrintDecimal            ; ... decimal
  162.         mov     DX,offset EndMsg        ; Get ptr final part of message
  163. Terminate:
  164.         mov     AH,9                    ; MS-DOS 'Print String'
  165.         int     21H                     ; ... DOS Entry Interrupt
  166.         mov     DX,offset Path          ; Restore directory to starting
  167.         mov     AH,3BH                  ; ... MS-DOS 'Change Subdirectory'
  168.         int     21H                     ; ... DOS Entry Interrupt
  169.         int     20H                     ; DOS Terminate Program
  170.  
  171. ;=========================================================================
  172. ; WalkTree is a recursive subroutine that processes each level of the
  173. ; directory hierarchy.  Each invocation of Walktree creates and uses a
  174. ; 50 byte stack frame containing the Segment and Offset of the prior
  175. ; level's DTA, the name of the current subdirectory, and a pointer to